package com.jihox.abookpro;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.jihox.abookpro.R;
import com.jihox.abookpro.domain.Order;
import com.jihox.abookpro.util.NetStatus;

public class SubmitFailActivity extends BaseActivity {
	
	private Order orderInfo = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.submit_fail);
		
		Intent intent = this.getIntent();
		Bundle bundle = intent.getExtras();
		
		orderInfo = (Order) bundle.getSerializable("orderInfo");
		
		TextView tvOrderId=  (TextView) findViewById(R.id.order_number);
		tvOrderId.setText(orderInfo.getOrderId());
		
		Button selectOrderButton = (Button)findViewById(R.id.btnSelectOrder);  
        Button reUploadButton = (Button)findViewById(R.id.btnReUpload); 
        Button returnButton = (Button)findViewById(R.id.btnReturn); 
        returnButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				
				Intent intent = new Intent();    
				intent.setClass(SubmitFailActivity.this, HomeChangeActivity.class);  
				SubmitFailActivity.this.startActivity(intent);
				finish();
			}
			
		});
        
        reUploadButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				if (NetStatus.getNetState(getApplicationContext()) == NetStatus.NET_NOT_PREPARE){
					Toast.makeText(SubmitFailActivity.this, getResources().getString(R.string.T_Try_Again_Net_Fail),
							Toast.LENGTH_SHORT).show();
					return;
				}
				Intent intent = new Intent();  
				intent.setClass(SubmitFailActivity.this, PaySuccessActivity.class); 
				Bundle bundle = new Bundle();
				bundle.putSerializable("orderInfo", orderInfo);
				intent.putExtras(bundle);
				SubmitFailActivity.this.startActivity(intent); 
				finish();
			}
		});
        
        selectOrderButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				
				Intent intent = new Intent();    
				intent.setClass(SubmitFailActivity.this, HomeChangeActivity.class); 
				intent.putExtra("FragmentIndex", 1);
				SubmitFailActivity.this.startActivity(intent);
			}
			
		});
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent();
			intent.setClass(SubmitFailActivity.this, HomeChangeActivity.class);
			SubmitFailActivity.this.startActivity(intent);
			finish();
		}
		return false;
	}
}
